import { BadRequestException, Injectable } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
import { ICurrentUserType } from 'src/decorators/current.user';

@Injectable()
export class AuthService {
  constructor(private readonly jwtService: JwtService) {}


  public generateToken(payload: ICurrentUserType): string {
    return this.jwtService.sign({ ...payload });
  }

  public verifyToken(token: string): ICurrentUserType {
    try {
      return this.jwtService.verify(token);
    } catch (e) {
      throw new BadRequestException('当前token无效');
    }
  }
}
